<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/6/10
 * Time: 18:51
 */
namespace app\common\model;

use think\Model;

class Article extends Model
{
    protected $table = 'wechatadmin.system_article';

    /**
     * 关联评论模型
     * @return \think\model\relation\HasMany
     */
    public function comments()
    {
        return $this->hasMany('ArticleComment','aid','id');
    }

    /**
     * 关联文章点赞模型
     * @return \think\model\relation\HasMany
     */
    public function good()
    {
        return $this->hasMany('ArticleGood','aid','id');
    }

    /**
     * 关联文章点赞模型
     * @return \think\model\relation\HasMany
     */
    public function collect()
    {
        return $this->hasMany('ArticleCollect','aid','id');
    }

    public function getArticleList($condition = [], $from=0, $size = 5)
    {
        if(!isset($condition['status']))
        {
            $condition['status'] = [
                'neq', config('code.status_delete')
            ];
        }

        $order = ['id' => 'desc'];

        $result = $this->where($condition)
//            ->field($this->_getListField())
            ->limit($from, $size)
            ->order($order)
            ->select();
        //echo $this->getLastSql();exit;
        return $result;
    }


}